home *** CD-ROM | disk | FTP | other *** search
/ CGI How-To / CGI HOW-TO.iso / chap5 / 5_2 / form_c / form.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-15  |  1.4 KB  |  78 lines

  1.  
  2. #include "parsehtm.h"
  3. #include <stdio.h>
  4.  
  5. void formHandler(String ts,String as,String et,Dictionary td)
  6. {
  7.     String value = 0;
  8.     
  9.     /* Find the current method if it exists */
  10.     
  11.     value = dict_valueForKey(td,"METHOD");
  12.                 
  13.     if(value)
  14.     {
  15.         string_setStringValue(value,"POST");
  16.     }
  17.     else/* No method, so add one */
  18.     {
  19.         value = string_alloc(5);
  20.         string_setStringValue(value,"POST");
  21.         dict_setValueForKey(td, "METHOD",value);
  22.     }
  23.     
  24.     /* Find the current action if it exists */
  25.     value = dict_valueForKey(td,"ACTION");
  26.                 
  27.     if(value)
  28.     {
  29.         string_setStringValue(value,"form");
  30.     }
  31.     else /* No action, so add one */
  32.     {
  33.         value = string_alloc(5);
  34.         string_setStringValue(value,"form");
  35.         dict_setValueForKey(td, "ACTION",value);
  36.     }
  37.     
  38.     /* Build a new tag string, and reset the old one to it */
  39.     
  40.     value = stringForTagDict(td);
  41.     
  42.     if(value)
  43.     {
  44.         string_setStringValue(ts,value->string);
  45.     
  46.         string_free(value);
  47.     }
  48. }
  49.  
  50. /* Test script */
  51.  
  52. void main(int argc, char *argv[])
  53. {
  54.     String output;
  55.  
  56.     /* Always do this first */
  57.     initializeHtmlParsingLibrary();
  58.     
  59.     /* Register the handler */
  60.     dict_setValueForKey(handlerDict,"FORM",formHandler);
  61.  
  62.     /* Parse the html file */
  63.     output = parseHtml("f2_c.htm");
  64.     
  65.     /* Output the parsed data */
  66.     if(output && output->string)
  67.     {
  68.         printf("Content-type: text/html\n\n");
  69.         fwrite(output->string,sizeof(char),strlen(output->string),stdout);
  70.         printf("\n");
  71.         
  72.         string_free(output);
  73.     }
  74.     
  75.     exit(0);
  76. }
  77.  
  78.